********************************************************************************
**  TITLE:      il1996_ines_contact_networks                                  **  
**  AUTHOR:	    Philippe Mongrain                                             **
**  DATA:       1996j                                                         **
**	DATE:		October 2022 					                              **	
**  VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "il1996_ines_contact_networks", replace

* Open the dataset

use "1996j.dta", clear 


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen sdate = .

replace sdate = 19960501 if cccc26 == 1
replace sdate = 19960502 if cccc26 == 2
replace sdate = 19960503 if cccc26 == 3
replace sdate = 19960504 if cccc26 == 4
replace sdate = 19960505 if cccc26 == 5
replace sdate = 19960506 if cccc26 == 6
replace sdate = 19960507 if cccc26 == 7
replace sdate = 19960508 if cccc26 == 8
replace sdate = 19960509 if cccc26 == 9
replace sdate = 19960510 if cccc26 == 10
replace sdate = 19960511 if cccc26 == 11
replace sdate = 19960512 if cccc26 == 12
replace sdate = 19960513 if cccc26 == 13
replace sdate = 19960514 if cccc26 == 14
replace sdate = 19960515 if cccc26 == 15
replace sdate = 19960516 if cccc26 == 16
replace sdate = 19960517 if cccc26 == 17
replace sdate = 19960518 if cccc26 == 18
replace sdate = 19960519 if cccc26 == 19
replace sdate = 19960520 if cccc26 == 20
replace sdate = 19960521 if cccc26 == 21
replace sdate = 19960522 if cccc26 == 22
replace sdate = 19960523 if cccc26 == 23
replace sdate = 19960524 if cccc26 == 24
replace sdate = 19960525 if cccc26 == 25
replace sdate = 19960526 if cccc26 == 26
replace sdate = 19960527 if cccc26 == 27

gen surveydate = sdate

format %tdMon_DD,_CCYY surveydate

gen electiondate = 19960529

format %tdMon_DD,_CCYY electiondate

gen time = (electiondate - surveydate) + 1 // Add 1 to correct for election date

* Gender

gen male = ccc56

recode male (2=0)

* Age

gen age = ccc57

replace age = . if age < 17

* Education

gen education = ccc63

* Party vote intention

gen partyvote = .

replace partyvote = 9999 if ccc23 == .
replace partyvote = 9999 if ccc23 == 19
replace partyvote = 9999 if ccc23 == 20
replace partyvote = 9999 if ccc23 == 21

replace partyvote = 1 if ccc23 == 2 & partyvote!=9999

replace partyvote = 0 if ccc23!=2 & partyvote!=1 & partyvote!=9999

replace partyvote = . if partyvote == 9999

label define partyvote 0 "Loser party vote" 1 "Winner party vote"
label values partyvote partyvote

* Prime minister vote intention

gen pmvote = .

replace pmvote = 9999 if ccc28 == .
replace pmvote = 9999 if ccc28 == 5
replace pmvote = 9999 if ccc28 == 6

replace pmvote = 1 if ccc28 == 1 & pmvote!=9999

replace pmvote = 0 if ccc28!=1 & pmvote!=1 & pmvote!=9999

replace pmvote = . if pmvote == 9999

label define pmvote 0 "Loser PM vote" 1 "Winner PM vote"
label values pmvote pmvote

* Preferred party (for party vote)

gen partypreferred = .

replace partypreferred = 9999 if cccc14 == .
replace partypreferred = 9999 if cccc14 == 19
replace partypreferred = 9999 if cccc14 == 20
replace partypreferred = 9999 if cccc14 == 21

replace partypreferred = 1 if cccc14 == 2 & partypreferred!=9999

replace partypreferred = 0 if cccc14!=2 & partypreferred!=1 & partypreferred!=9999

replace partypreferred = . if partypreferred == 9999

label define partypreferred 0 "Loser preferred vote" 1 "Winner preferred vote"
label values partypreferred partypreferred

* Preferred party (for prime minister vote)

gen pmpreferred = .

replace pmpreferred = 9999 if cccc14 == .
replace pmpreferred = 9999 if cccc14 == 19
replace pmpreferred = 9999 if cccc14 == 20
replace pmpreferred = 9999 if cccc14 == 21

replace pmpreferred = 1 if cccc14 == 1 & pmpreferred!=9999

replace pmpreferred = 0 if cccc14!=1 & pmpreferred!=1 & pmpreferred!=9999

replace pmpreferred = . if pmpreferred == 9999

label define pmpreferred 0 "Loser preferred PM" 1 "Winner preferred PM"
label values pmpreferred pmpreferred

* Political discussion

gen discussion = 4 - cc45

gen discussion_3pts = discussion
replace discussion_3pts = 0 if discussion == 1
replace discussion_3pts = 1 if discussion == 2
replace discussion_3pts = 2 if discussion == 3

* Political disagreement

gen disagreement = cc46

recode disagreement (5=.)

replace disagreement = disagreement - 1

gen disagreement_3pts = disagreement
replace disagreement_3pts = 0 if disagreement == 1
replace disagreement_3pts = 1 if disagreement == 2
replace disagreement_3pts = 2 if disagreement == 3


*********************************
** NATIONAL-LEVEL EXPECTATIONS **
*********************************

* Prime Minister: Netanyahu or Peres? (1 = Netanyahu, 2 = Peres)

gen pm = ccc35

gen correct_pm = 0 if pm!=1 & pm!=.
replace correct_pm = 1 if pm == 1

* Largest party in the next Knesset (1 = Labor, 2 = Likud)

gen largest = ccc36

gen correct_largest = 0 if largest!=1 & largest!=.
replace correct_largest = 1 if largest == 1


**********
** SAVE **
**********

save "il1996_ines.dta", replace


********************
** MAIN ANALSYSES **
********************

* Regression analysis and percentage of correct and incorrect forecasts (largest party)

logistic correct_largest discussion disagreement i.partyvote age i.male education time
estimates table, star(.05 .01 .001)

tab correct_pm if e(sample) == 1

* Regression analysis and percentage of correct and incorrect forecasts (prime minister)

logistic correct_pm discussion disagreement i.pmvote age i.male education time
estimates table, star(.05 .01 .001)

tab correct_pm if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_largest "Largest party (DV)"
label variable correct_pm "Prime minister (DV)"
label variable discussion "Discussion"
label variable disagreement "Disagreement"
label variable partyvote "Party vote"
label variable pmvote "PM vote"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"

quietly logistic correct_largest discussion disagreement i.partyvote age i.male education time

estpost tabstat correct_largest discussion disagreement partyvote age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "il1996_ines_summary_national_largest.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 1996 Israeli legislative election (INES) (largest party), national level") replace

eststo clear

quietly logistic correct_pm discussion disagreement i.pmvote age i.male education time

estpost tabstat correct_pm discussion disagreement pmvote age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "il1996_ines_summary_national_pm.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 1996 Israeli legislative election (INES) (prime minister), national level") replace

eststo clear

log close